package com.yzzrjy.old;

import java.io.*;
import java.util.Properties;

public class configUtils {

    public static String getNewUid() throws IOException {
        long oldTime = System.currentTimeMillis();

        Properties properties = new Properties();
        InputStream resourceAsStream = configUtils.class.getClassLoader().getResourceAsStream("config.properties");
        properties.load(resourceAsStream);
        resourceAsStream.close();

        String path = configUtils.class.getClassLoader().getResource("config.properties").getPath();
        File file = new File(path);
        OutputStream outputStream = new FileOutputStream(file);

        String keyUid = "startUid";
        String keyLength = "addLength";

        Object startUid = properties.get(keyUid);
        Object addLength = properties.get(keyLength);
        long start = Long.parseLong(startUid.toString());
        int length = Integer.parseInt(addLength.toString());

        String newValue = String.valueOf((start + length));


        properties.setProperty(keyUid, newValue);
        properties.store(outputStream, "Update ‘" + keyUid + "‘+ ‘"+newValue);
        outputStream.close();
        System.out.println(System.currentTimeMillis() - oldTime);
        return newValue;
    }
}
